package com.xspace.android.xafcommon.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class BeanUtils {
	public static long getId(Object bean) {
		try {
			Method method = bean.getClass().getMethod("getId");
			return (Long) method.invoke(bean);
		} catch (Exception e) {
			try {
				Field field = bean.getClass().getField("id");
				long id = field.getLong(bean);
				return id;
			} catch (Exception e1) {
				e.printStackTrace();
				return -1;
			}
		}
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T invokeMethod(Object obj, String methodName) {
		try {
			Object invoke = obj.getClass().getMethod(methodName).invoke(obj);
			return (T) invoke;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
